package com.itheima.demo;

import com.itheima.domain.Person;
import com.itheima.mapper.One2OneMapper;
import com.itheima.utils.MapperUtils;
import org.apache.ibatis.session.SqlSession;

import java.io.IOException;
import java.util.List;

/*
    测试类
 */
public class One2OneDemo {

    //创建工具类对象
    public static MapperUtils mapperUtils = new MapperUtils();

    public static void main(String[] args) throws IOException {
        //通过工具类获取SqlSession对象
        SqlSession sqlSession = mapperUtils.getSqlSession("MyBatisConfig.xml");
        //获取映射对象
        One2OneMapper mapper = sqlSession.getMapper(One2OneMapper.class);
        //调用方法
        List<Person> ps = mapper.findAll();
        for (Person p : ps) {
            System.out.println("姓名: " + p.getName() + "  身份证: "+p.getC().getNumber());
        }
        //释放资源
        mapperUtils.closeResource();
    }
}
